#include<bits/stdc++.h>
using namespace std;
const int N=1002;

int n,m;
char arr[N][N];
int minn[N][N];
short dp[N][N][2];

struct Node{
    int r,c;
    int way,w;
    Node(){}
    Node(int r,int c,int way,int w){
        this->r=r;
        this->c=c;
        this->way=way;
        this->w=w;
    }
    bool operator<(const Node& node) const{
        return w>node.w;
    }
};

int main(){
    cin>>m>>n;
    for(int i=0;i<m;i++){
        string str;
        cin>>str;
        for(int j=0;str[j]!='\0';j++){
            arr[i][j]=str[j];
        }
    }
    memset(minn,0x3f,sizeof(minn));
    priority_queue<Node> que;
    que.push(Node(0,0,2,-1));
    minn[0][0]=0;
    while(!que.empty()){
        Node node=que.top();
        que.pop();
        int r=node.r;
        int c=node.c;
        int way=node.way;
        int w=node.w;
        if(w>minn[r][c]) continue;
        //printf("%d %d %d %d\n",r,c,way,w);
        for(int i=0;i<=1;i++){
            int r1,c1;
            //right
            if(i==0) {
                r1=r;
                c1=c+1;
            }
            //down
            if(i==1){
                r1=r+1;
                c1=c;
            }
            if(r1<0||r1>=m) continue;
            if(c1<0||c1>=n) continue;
            if(arr[r1][c1]=='#') continue;
            int w1;
            if(i!=way) w1=w+1;
            else w1=w;
            if(w1<=minn[r1][c1]){
                minn[r1][c1]=w1;
                que.push(Node(r1,c1,i,w1));
            }
        }
    }
    if(minn[m-1][n-1]>3000){
        printf("-1");
        return 0;
    }
    //maxn
    memset(dp,0,sizeof(dp));
    for(int i=1;i<m;i++){
        for(int j=1;j<n;j++){
            if(arr[i][j]=='#') continue;
            //0 right
            if(arr[i][j-1]=='#'){
                dp[i][j][0]=0;
            }
            else if(dp[i][j-1][0]<dp[i][j-1][1]+1){
                dp[i][j][0]=dp[i][j-1][1]+1;
            }else{
                dp[i][j][0]=dp[i][j-1][0];
            }
            //1 down
            if(arr[i-1][j]=='#'){
                dp[i][j][1]=0;
            }
            else if(dp[i-1][j][1]<dp[i-1][j][0]+1){
                dp[i][j][1]=dp[i-1][j][0]+1;
            }else{
                dp[i][j][1]=dp[i-1][j][1];
            }
        }
    }
    printf("%d %d",max(dp[m-1][n-1][0],dp[m-1][n-1][1]),minn[m-1][n-1]);
    return 0;
}